package com.kcwx.web.controller.monitor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.kcwx.common.annotation.Log;
import com.kcwx.common.core.controller.BaseController;
import com.kcwx.common.core.domain.AjaxResult;
import com.kcwx.common.core.page.TableDataInfo;
import com.kcwx.common.enums.BusinessType;
import com.kcwx.common.utils.poi.ExcelUtil;
import com.kcwx.system.domain.SysOperLog;
import com.kcwx.system.service.ISysOperLogService;

import com.kcwx.shareddomain.common.dto.DeleteDto;
import com.kcwx.shareddomain.common.dto.DelParaValid;
import com.kcwx.shareddomain.system.query.SysOperLogQuery;

/**
 * 操作日志记录
 * 
 */
@Api(tags = "系统管理-日志管理")
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController
{
    @Autowired
    private ISysOperLogService operLogService;
    
    @ApiOperation("获取日志分页列表")
    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody SysOperLogQuery operLog)
    {
        startPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return success(getDataTable(list));
    }

    @ApiOperation("导出")
    @Log(title = "导出操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLogQuery operLog)
    {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @ApiOperation("批量删除操作日志")
    @Log(title = "批量删除操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/batchRemove")
    public AjaxResult batchRemove(@RequestBody DeleteDto dto)
    {
        Long []ids=DelParaValid.validBatchDel(dto);
        int rowsAffect=operLogService.deleteOperLogByIds(ids);
        return rowsAffect>0?success():error("删除失败");
    }

    @Log(title = "清空操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        operLogService.cleanOperLog();
        return success();
    }
}
